/* -*-  Mode:C; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
/*
 * Copyright (c) 1999, 2000 Massachusetts Institute of Technology.
 *
 * This software is being provided by the copyright holders under the GNU
 * General Public License, either version 2 or, at your discretion, any later
 * version. (See the file `LICENSE' in the source distribution.)
 *
 * This software is provided "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The entire risk as
 * to the quality and performance of the program is with you. See the GNU
 * General Public License for more details.
 *
 * The name and trademarks of copyright holders may NOT be used in 
 * advertising or publicity pertaining to the software without specific, 
 * written prior permission. Title to copyright in this software and any 
 * associated documentation will at all times remain with copyright 
 * holders. See the file CMAUTHORS which should have accompanied this software 
 * for a list of all copyright holders. 
 * 
 * Particular files in this distribution may be derived from previously
 * copyrighted software. This copyright applies only to those changes made by
 * the copyright holders listed in the CMAUTHORS file.
 */
/*
 * An implementation of the Congestion Manager (CM) for Linux.  This
 * file implements the CM timers.  (Currently it contains only events
 * that get called on a timeout but more generically it must also
 * contain routines to schedule a timeout; that code is currently
 * embedded in cm files.)  */

#include <linux/config.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/malloc.h>
#include <net/sock.h>
#include <net/cm.h>
#include <net/cm_debug.h>


/* This function gets called when no update has happened for a flow
 * for RTO. In that case, probably ack all the data as loss. Also, we
 * need to exponentially backoff timer here in case of absence of
 * updates. Also, terminate this flow if it hasn't updated for very
 * very long */

void cm_update_timeout(unsigned long data)
{
	cm_flow_t *flow = (cm_flow_t *)data;
	printk("cm_update timeout called \n");
	/* extract out inflight and then do cm_update(...PERSISTENT, inflight)
	 */
	cm_update(flow, flow->inflight, 0, CM_PERSISTENT, 0);
	/* what happens if app updates later 
	 * should we notify the app of update done by CM for it 
	 * Also make sure inflight is the right value to put in here
	 */
} 


/* This function gets called when no notify happens for a flow for 1
 * rtt after cm_request is granted. In that case, take away the
 * request granted i.e. change pending to REQUEST_NOT_GRANTED and
 * schedule another flow instead.*/

void cm_request_timeout(unsigned long data)
{
        cm_flow_t *flow = (cm_flow_t *)data;
	printk("cm_request timed out\n");
	/* should we make request inactive or keep it active */
	/* inactive is the best and safest, let app do request again */
	flow->pending = CM_REQUEST_INACTIVE;
	/* should application be notified of this? */
	/* schedule another flow */
	cms_schedule(&flow->mflow->sched);
}

/* This function gets called when macroflow has been inactive for a while */

void cm_restart_timeout(unsigned long data)
{
        cm_macroflow_t *mflow = (cm_macroflow_t *)data;
	printk("cm_restart_timeout called\n");
	cmcc_restart(mflow->congctl);
}
